import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { DictEnum } from '@vben/constants';
import { getPopupContainer } from '@vben/utils';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';
import { h } from 'vue';
import { Image } from 'ant-design-vue';
import dayjs from 'dayjs';

// 查询表单配置
export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    componentProps: { placeholder: '请输入名称', allowClear: true },
    fieldName: 'name',
    label: '名称',
  },
  {
    component: 'Input',
    componentProps: { placeholder: '请输入年龄', allowClear: true },
    fieldName: 'age',
    label: '年龄',
  },
  {
    component: 'Select',
    componentProps: {
      getPopupContainer,
      placeholder: '请选择状态(0正常1停用)',
      options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
    },
    fieldName: 'status',
    label: '状态(0正常1停用)',
  },
];

// 弹窗表单配置
export const modalSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入编号',
    },
    fieldName: 'id',
    label: '编号',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入名称',
    },
    fieldName: 'name',
    label: '名称',
    rules: 'required',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入年龄',
    },
    fieldName: 'age',
    label: '年龄',
    rules: 'required',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
    },
    fieldName: 'status',
    label: '状态(0正常1停用)',
    rules: 'required',
  },
];

// 抽屉表单配置
export const drawerSchema: FormSchemaGetter = () => {
  // 和弹窗共用
  return modalSchema();
};

// 表格列配置
export const columns: VxeGridProps['columns'] = [
  // 复选框列
  { type: 'checkbox', width: 50 },
  { title: '编号', field: 'id', width: 100 },
  { title: '名称', field: 'name' },
  { title: '年龄', field: 'age' },
  {
    field: 'status',
    slots: { 
      default: function(params) {
        return renderDict(params.row.status, DictEnum.SYS_NORMAL_DISABLE);
      }
    },
    title: '状态(0正常1停用)',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 150,
  },
]; 